package cc.ilzy.mall.user.service.impl;

import cc.ilzy.mall.user.constants.Constants;
import cc.ilzy.mall.user.service.IMailService;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.bcel.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MailServiceImpl implements IMailService {
    @Autowired
    private JavaMailSender mailSender;

    @Override
    @Async
    public void sendMail(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        message.setFrom(Constants.MAIL_USERNAME);
        log.info("form: {} send email to:{}, message: {}", Constants.MAIL_USERNAME, to, content);
        mailSender.send(message);

    }
}
